package com.daocao.hua.api.requestInfo;

import com.daocao.hua.api.Api;
import com.daocao.hua.api.bean.IdCardIndentityBean;
import com.daocao.hua.api.bean.UploadSubmitIdcardBean;
import com.daocao.hua.api.callback.AutonymContract;
import com.daocao.hua.model.IdentityModel;
import com.daocao.hua.util.Network;
import com.daocao.hua.util.RxLifeUtil;
import com.daocao.hua.util.ToastUtil;

/**
 * Created by Administrator on 2017/5/14.
 */

public class AutonymRequest extends BaseRequest<AutonymContract.View> implements AutonymContract.Presenter<AutonymContract.View> {

    public static AutonymRequest create() {
        return new AutonymRequest();
    }


    @Override
    public void getSubmitidCard(String name, String idcard, UploadSubmitIdcardBean item) {
        if (!Network.checkNetwork(BaseContext)) {
            ToastUtil.makeText(BaseContext, networkFail).show();
            return;
        }
        mView.onRequestStart();
        Api.api_service.getSubmitidCard(item).compose(RxLifeUtil.checkOn(BaseContext)).
                doFinally(() -> {
                    try {
                        mView.complete();
                    } catch (NullPointerException e) {

                    }
                }).
                subscribe(result -> {
                    mView.getSubmitidCardSuccess(name, idcard, result);
                });
    }

    @Override
    public void getIdentityInfo(int paramInt, String paramString) {
        if (!Network.checkNetwork(BaseContext)) {
            ToastUtil.makeText(BaseContext, networkFail).show();
            return;
        }
        mView.onRequestStart();
        IdCardIndentityBean bean = new IdCardIndentityBean();
        bean.img = paramString;
        Api.api_service.getIdentityInfo(paramInt, bean).compose(RxLifeUtil.checkOn(BaseContext)).
                doFinally(() -> {
                    try {
                        mView.complete();
                    } catch (NullPointerException e) {

                    }
                }).
                subscribe(result -> {
                    if (result.getStatus() != 0) {
                        mView.getIdentityInfoSuccess(result);
                    } else {
                        mView.getIdentityInfoFail(result.getMsg());
                    }
                });
    }
}
